<template>
  <div class="assess-object">
    <ObjectTable :source="indexList" @search-list="searchData" @edit-scheme="editIndex">
      <pagination
        slot="pagination"
        :page-size.sync="pageParam.pageSize"
        :total="pageParam.totalSize"
        :current-page.sync="pageParam.currentPage"
        :pageSizes="[10, 20]"
        layout="slot,prev, pager, next, sizes, jumper"
        @change="onPageChange"></pagination>
    </ObjectTable>

    <ObjectEditDailog
      :visible.sync="showDialog"
      :userData="userInfo"
      :userStatus="userStatus"
      :userIdentity="userIdentity"
      @submit="onModuleAdd"></ObjectEditDailog>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import pagination from '@com/pagination'
import ObjectTable from './components/ObjectTable'
import ObjectEditDailog from './components/ObjectEditDailog'
import { getqueryAssessUser, queryUiasCodeInfo } from '@apis/assessManage.js'
import { cloneDeep } from 'lodash'
export default {
  name: 'AssessObject',
  components: { pagination, ObjectTable, ObjectEditDailog },
  props: {},
  data() {
    return {
      pageParam: {
        pageSize: 10,
        currentPage: 1,
        totalSize: 0,
      },
      searchParam: {
        tenantId: '',
        year: '',
        quarter: '',
        busPeriod: '',
        isRefresh: '0',
        keywords: '',
        labelCode: '',
        orgId: '',
        status: '',
        type: '',
        userId: '',
      },
      indexList: [],
      showDialog: false,
      userInfo: {},
      userStatus: [],
      userIdentity: [],
    }
  },
  watch: {
    schemeInfo: {
      handler() {
        this.searchParam.year = this.schemeInfo.year
        this.searchParam.quarter = this.schemeInfo.quarter
        this.initData()
        this.getList()
      },
      deep: true,
    },
  },
  computed: {
    ...mapGetters('indReview', ['schemeInfo']),
  },
  created() {},
  mounted() {
    if (this.schemeInfo) {
      this.searchParam.isRefresh = '0'
      this.searchParam.year = this.schemeInfo.year
      this.searchParam.quarter = this.schemeInfo.quarter
      this.initData()
      this.getList()
    }
  },
  methods: {
    searchData(data) {
      this.searchParam = Object.assign(this.searchParam, data)
      this.pageParam.currentPage = 1
      this.initData()
    },
    editIndex(data) {
      this.searchParam.isRefresh = '0'
      this.userInfo = cloneDeep(data)
      this.showDialog = true
    },
    onPageChange(obj) {
      this.searchParam.isRefresh = '0'
      this.pageParam.currentPage = obj.pageNumber
      this.pageParam.pageSize = obj.pageSize
      this.initData()
    },
    async initData() {
      const { status, data } = await getqueryAssessUser(
        this.searchParam,
        this.pageParam.currentPage,
        this.pageParam.pageSize
      )
      if (status === 200 && data) {
        this.indexList = data.assessUserPage.content
        this.pageParam.totalSize = data.assessUserPage.totalSize
      }
    },
    getList() {
      queryUiasCodeInfo({
        occurrenceTime: '',
        oneParam: 'user_status',
        tenantId: localStorage.pskh_tenantId,
      }).then(res => {
        this.userStatus = res.data
      })
      queryUiasCodeInfo({
        occurrenceTime: '',
        oneParam: 'user_identity',
        tenantId: localStorage.pskh_tenantId,
      }).then(res => {
        this.userIdentity = res.data
      })
    },
    onModuleAdd() {
      this.searchParam.isRefresh = '0'
      this.initData()
    },
  },
}
</script>
<style lang="scss" scoped>
.assess-object {
  height: 100%;
}
</style>
